package net.sf.rose.file.xml.validate;

import java.io.InputStream;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.SchemaFactory;

import org.dom4j.io.SAXReader;

public class Dom4jTest {

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		InputStream xsd = Dom4jTest.class.getResourceAsStream("test.xsd");
		InputStream xml = Dom4jTest.class.getResourceAsStream("test.xml");

		SAXParserFactory factory = SAXParserFactory.newInstance();
		SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
		factory.setSchema(schemaFactory.newSchema(new Source[] { new StreamSource(xsd) }));
		SAXParser parser = factory.newSAXParser();
		SAXReader reader = new SAXReader(parser.getXMLReader());
		reader.setValidation(false);
		reader.setErrorHandler(new SimpleErrorHandler());
		reader.read(xml);
	}

}
